package ${dtoPkg};

<#--导包-->
<#compress>
<#if GeneratorInfo.hasSwagger == "1">
import io.swagger.v3.oas.annotations.media.Schema;
</#if>
<#if hasDateFormat == true>
    import org.springframework.format.annotation.DateTimeFormat;
</#if>

import lombok.Data;
import cn.lycode.common.utils.SecurityUtils;
import ${entityPkg}.${entityClassName};
import java.util.Date;
<#list importPackages as pkg>
import ${pkg};
</#list>


</#compress>

/**
 * ${entityClassName}添加DTO
 *
 * @since ${datetime}
 * @author ${author}
 */
@Data
<#if GeneratorInfo.hasSwagger == "1">
@Schema(description = "${entityClassName}添加DTO")
</#if>
public class ${dtoAddClassName} {

<#list columns as field>
<#--   遍历所有的列， addDTO只映射 插入标志为 1 的字段-->
    <#if field.isInsert == "1" >
    <#if field.javaType == "LocalDateTime" >
    <#if GeneratorInfo.hasSwagger == "1">
    @Schema(description =  "${field.columnComment}")
    </#if>
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private ${field.javaType} ${field.javaField}; //${field.columnComment}
 <#else>
    <#if GeneratorInfo.hasSwagger == "1">
    @Schema(description =  "${field.columnComment}")
    </#if>
    private ${field.javaType} ${field.javaField}; //${field.columnComment}
    </#if>
    </#if>
</#list>

<#--addDTO转Entity-->
    public ${entityClassName} buildAddEntity() {
        ${entityClassName} ${camelClassName} = new ${entityClassName}();
        <#list columns as field>
            <#if field.isInsert == "1" >
        ${camelClassName}.set${field.upCamelField}(this.${field.javaField});
            </#if>
        </#list>
        ${camelClassName}.setCreateTime(new Date());
        ${camelClassName}.setCreateBy(SecurityUtils.getLoginUsername());
        return ${camelClassName};
    }
}

